package com.example.springbootstudy.service.impl;

import com.example.springbootstudy.Mapper.DeptMapper;
import com.example.springbootstudy.dao.impl.DeptDaoImpl;
import com.example.springbootstudy.pojo.Dept;
import com.example.springbootstudy.pojo.Manager;
import com.example.springbootstudy.pojo.Result;
import com.example.springbootstudy.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    DeptDaoImpl deptDaoImpl;
//    注入DeptMapper实例，用于和数据库交互。
    @Autowired
    DeptMapper deptMapper;

    @Override
    public String addService(String ask) {
        if(ask.equals("用户传来需求了")){
            String s = deptDaoImpl.addDao("访问数据库");
            return s;
        }
       return  null;
    }

    @Override
    public List<Dept> selectAllService() {
        return deptMapper.selectAllMapper();

    }

    @Override
    public void delOneService(Integer id) {
        deptMapper.delOneDao(id);
    }

    @Override
    public void insertService(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertMapper(dept);
    }

    @Override
    public Dept getOneService(Integer id) {
        return deptMapper.getOneMapper(id);
    }

    @Override
    public void updateService(Dept dept) {
        /*dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());*/
        deptMapper.updateMapper(dept);
    }

    @Override
    public Manager adminService(Manager manager) {
       return deptMapper.adminMapper(manager);
    }
}